package com.dynaBlaster.view;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.dynaBlaster.R;
import com.dynaBlaster.elements.Bomb;

public class BombView extends BaseView {

	Bitmap bomb_bitmap;
	Bitmap expl_centre;
	Bitmap expl_end_n;
	Bitmap expl_end_s;
	Bitmap expl_end_w;
	Bitmap expl_end_e;
	Bitmap expl_middle_vert;
	Bitmap expl_middle_hor;
	
	public BombView(GameView view){
		super(view);
		
		Resources r = view.getR();
		
		bomb_bitmap = loadImg(r.getDrawable(R.drawable.bomb));
		
		expl_centre = loadImg(r.getDrawable(R.drawable.bomb_expl));
		expl_end_n = loadImg(r.getDrawable(R.drawable.bomb_expl_up));
		expl_end_s = loadImg(r.getDrawable(R.drawable.bomb_expl_down));
		expl_end_w = loadImg(r.getDrawable(R.drawable.bomb_expl_left));
		expl_end_e = loadImg(r.getDrawable(R.drawable.bomb_expl_right));
		expl_middle_vert = loadImg(r.getDrawable(R.drawable.bomb_expl_mid_vert));
		expl_middle_hor = loadImg(r.getDrawable(R.drawable.bomb_expl_mid_hor));
	}
	

	// @Override
	public void draw(Canvas canvas, Bomb bomb) {
		int field_corner_x = bomb.pos.x - bomb.size, field_corner_y = bomb.pos.y - bomb.size;
		switch (bomb.state) {
		case Bomb.STATE_TICKING:
			canvas.drawBitmap(bomb_bitmap, field_corner_x, field_corner_y, new Paint());
			break;
		case Bomb.STATE_EXPLODING:
			canvas.drawBitmap(expl_centre, field_corner_x, field_corner_y, new Paint());

			int u = view.screenTileSize;

			// draw ends
			if (bomb.range_n > 0)
				canvas.drawBitmap(expl_end_n, field_corner_x, field_corner_y - bomb.range_n * u, new Paint());
			if (bomb.range_s > 0)
				canvas.drawBitmap(expl_end_s, field_corner_x, field_corner_y + bomb.range_s * u, new Paint());
			if (bomb.range_e > 0)
				canvas.drawBitmap(expl_end_e, field_corner_x + bomb.range_e * u, field_corner_y, new Paint());
			if (bomb.range_w > 0)
				canvas.drawBitmap(expl_end_w, field_corner_x - bomb.range_w * u, field_corner_y, new Paint());

			// draw explosion middles
			for (int i = 1; i < bomb.range_n; i++) {// N
				canvas.drawBitmap(expl_middle_vert, field_corner_x, field_corner_y - i * u, new Paint());
			}
			for (int i = 1; i < bomb.range_s; i++) {// S
				canvas.drawBitmap(expl_middle_vert, field_corner_x, field_corner_y + i * u, new Paint());
			}
			for (int i = 1; i < bomb.range_e; i++) {// E
				canvas.drawBitmap(expl_middle_hor, field_corner_x + i * u, field_corner_y, new Paint());
			}
			for (int i = 1; i < bomb.range_w; i++) {// W
				canvas.drawBitmap(expl_middle_hor, field_corner_x - i * u, field_corner_y, new Paint());
			}

			break;
		case Bomb.STATE_DEAD:
			break;
		}

	}
	
}
